package h0805;

import java.util.*;

/**
 * @author 不知名帅哥
 * @version 1.0
 * @description Wonderland
 * @date 2024/8/5 17:41
 */
public class Wonderland {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        //票价种类
        int[] costs = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        //日期
        int[] days = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();

        System.out.println(minCost(costs, days));

    }

    //动态规划解法
    public static int minCost(int[] costs, int[] days) {
        int maxDay = days[days.length - 1];
        //TODO dp[i]表示，到当前日期i的最少花费钱数
        int[] dp = new int[maxDay + 1];

        int index = 0;
        for (int i = 1; i <=maxDay; i++) {
            if (i != days[index]) {
                dp[i] = dp[i - 1];
            } else {
                //一日票
                int pay1 = costs[0] + dp[i - 1];

                //三日票
                int pay3 = costs[1] + (i >= 3 ? dp[i - 3] : 0);
                //七日票
                int pay7 = costs[2] + (i >= 7 ? dp[i - 7] : 0);

                //月票
                int pay30 = costs[3] + (i >= 30 ? dp[i - 30] : 0);

                dp[i] = Math.min(Math.min(pay1, pay3), Math.min(pay7, pay30));

                //匹配下一个游玩日
                index++;
            }
        }
        return dp[maxDay];
    }
}
